/**
 * Created by Administrator on 2018-01-24.
 */

package test

import kotlinx.coroutines.experimental.*



fun main(args: Array<String>) {
    tcoro3()
}

fun coro1(msg: String="world!" ): Job {
    msg.let {  }
    val job = launch {
        if (false) {
            delay(1000)
            println(msg)
        }
        else sup1()
    }
    println("hello")
    return job
}

suspend fun sup1() {
    delay(1000)
    println("world! suspend")
}

fun tcoro1() {
    coro1()
    Thread.sleep(1000)
}

fun tcoro2() = runBlocking<Unit> {
    coro1()
    delay(2000)
}

fun tcoro3() = runBlocking<Unit> {
    val job = coro1()
    job.join()
}

fun tcoroLotJobs() = runBlocking {
    val jobs = List(100_000) {
        coro1(".")
    }
}



